package com.aids_malaria.widget.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.TextView;

import com.aids_malaria.R;
import com.aids_malaria.adapter.NumberDataAdapter;
import com.aids_malaria.base.BaseQuickAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class NumDialog extends Dialog {

    @BindView(R.id.rv_data)
    RecyclerView rv_data;

    private NumberDataAdapter numberDataAdapter;
    List<Integer> mData = new ArrayList<>();

    public NumDialog(@NonNull Context context,int dataSize,OnNumClickListener onNumClickListener) {
        super(context);
        setContentView(R.layout.dialog_num);
        ButterKnife.bind(this,this);
        this.onNumClickListener = onNumClickListener;
        if(dataSize <= 5){
            mDataSize = 5;
        }else{
            mDataSize  = dataSize;
        }
        for(int i=1;i<=mDataSize;i++){
            mData.add(i);
        }
        rv_data.setLayoutManager(new LinearLayoutManager(context));
        numberDataAdapter = new NumberDataAdapter(context,R.layout.item_number_data,mData);
        rv_data.setAdapter(numberDataAdapter);
        numberDataAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                onNumClickListener.onNumClick(mData.get(position),NumDialog.this);
            }
        });

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        WindowManager.LayoutParams attributes = getWindow().getAttributes();
        attributes.width = ViewGroup.LayoutParams.WRAP_CONTENT;
        attributes.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        getWindow().setAttributes(attributes);
        getWindow().setGravity(Gravity.CENTER);
    }

    public interface OnNumClickListener{
        void onNumClick(int num,Dialog dialog);
    }

    private OnNumClickListener onNumClickListener;
    private int mDataSize;

}
